package com.demo.crm.model;

import lombok.Data;

import javax.servlet.http.HttpServletRequest;
import java.util.Set;

/**
 * 当前用户标识
 *
 * @author tanshuai
 */
@Data
public class UserToken {

    /**
     * 代表当前用户
     */
    private String userKey;

    /**
     * 当前用户信息
     */
    private Object principal;

    /**
     * 当前用户具有的授权信息
     */
    private Set<String> authorities;

    public static UserToken getUserToken(HttpServletRequest request) {
        return (UserToken) request.getSession().getAttribute("userToken");
    }

    public boolean has(String authority) {
        return authorities != null && authorities.contains(authority);
    }
}
